/**
 * 抛异常公共函数，用于请求接口或其他异常捕捉错误信息
 * @param callFun 调用函数，用于记录错误调用来源 ，一般复制当前啊函数名称，或者填入说明信息 login/getVerifyCode
 * @param e 错误消息
 * @param title alert和notice模块选填，错误标题
 * @param log 是否打印到控制台
 */
/**
 * 数组转对象值
 */
export function arrToObj(arr = [], keyCode = 'id', valueCode = 'name') {
    const map = new Map()
    if (arr.length === 0) return {}
    arr.forEach(item => {
      map.set(item[keyCode], item[valueCode])
    })
    const obj = {}
    for (const [k, v] of map) {
      obj[k] = v
    }
    return obj
  }
  export function throwError(callFun, e, title, log = true) {
    if (e.statusCode === 401) {
      Notice.warning({ title: title || '提示', message: e.message || '操作错误！' })
    } else {
      Notice.error({ title: title || '错误', message: e.message || '操作错误！' })
    }
    if (log) {
      const str = callFun.split('/')
      if (str && str.length >= 2) {
        Utils.log.pretty(str[0], str[1], 'danger')
      }
      console.log(e)
      Utils.log.danger('----------------------------------------------------------')
    }
  }
  export function datefilter(val){
    if (val) {
      var date = new Date(parseInt(val) * 1000);
      var Year = date.getFullYear();
      var Moth =
        date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1;
      var Day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var Hour =
        date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
      var Minute =
        date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
      var Sechond =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      var GMT =
        Year +
        "-" +
        Moth +
        "-" +
        Day +
        "   " +
        Hour +
        ":" +
        Minute +
        ":" +
        Sechond;

      return GMT;
    } else {
      return "";
    }
  }